/*
 * Copyright (c)e 2024-2024.Powered by neflibata
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.liuzian.marketserver.controller;

import com.liuzian.marketserver.dto.R;
import com.liuzian.marketserver.entity.*;
import com.liuzian.marketserver.service.serviceImpl.CommodityServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/commodity")
public class CommodityController {
    @Autowired
    private CommodityServiceImpl commodityServiceImpl;

    /**
     * 查询商品 通过搜索框
     *
     * @param name 商品名称
     * @return R
     */
    @GetMapping("/name")
    public R<List<Commodity>> queryCommodityByName(String name) {
        return commodityServiceImpl.queryCommodityByName(name);
    }

    /**
     * 查询商品 通过搜索框
     *
     * @param type 商品种类
     * @return R
     */
    @GetMapping("/type")
    public R<List<Commodity>> queryCommodityByType(String type) {
        return commodityServiceImpl.queryCommodityByType(type);
    }

    /**
     * 查询商品 通过搜索框
     *
     * @param gid 商品id
     * @return R
     */
    @GetMapping("/gid")
    public R<Commodity> queryCommodityByGid(Long gid) {
        return commodityServiceImpl.queryCommodityByGid(gid);
    }

    @GetMapping("/current")
    public R<List<Commodity>> newCommodity() {
        return commodityServiceImpl.newCommodity();
    }

    /**
     * 查询所有商品
     *
     * @return R
     */
    @GetMapping("/all")
    public R<List<Commodity>> queryCommodity() {
        return commodityServiceImpl.queryCommodity();
    }

    /**
     * 查询所有商品
     *
     * @param uid 用户uid
     * @return R
     */
    @GetMapping("/uid")
    public R<List<Commodity>> queryCommodityByUid(Long uid) {
        return commodityServiceImpl.queryCommodityByUid(uid);
    }

    /**
     * 添加商品
     *
     * @param commodity 商品对象
     * @return R
     */
    @PostMapping("/add")
    public R<Commodity> addCommodity(@RequestBody Commodity commodity) {
        return commodityServiceImpl.addCommodity(commodity);
    }

    @GetMapping("/verify")
    public R<List<Commodity>> verifyCommodity() {
        return commodityServiceImpl.verifyCommodity();
    }

    @GetMapping("/auth")
    public R<String> authCommodity(Long gid) {
        return commodityServiceImpl.authCommodity(gid);
    }

    @GetMapping("/refuse")
    public void refuseCommodity(Long gid) {
        commodityServiceImpl.refuseCommodity(gid);
    }

    @GetMapping("/browse")
    public void browseCommodity(Long gid) {
        commodityServiceImpl.browseCommodity(gid);
    }

    @GetMapping("/delete")
    private R<String> deleteCommodity(Long gid) {
        return commodityServiceImpl.deleteCommodity(gid);
    }

    @GetMapping("/pause")
    private R<String> pauseCommodity(Long gid) {
        return commodityServiceImpl.pauseCommodity(gid);
    }
}
